package com.btex.app.treaty.dialog;

import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.util.DisplayMetrics;
import android.view.Gravity;
import android.view.View;
import android.view.WindowManager;
import android.widget.TextView;

import com.btex.app.Config;
import com.btex.app.R;
import com.btex.app.WebActivity;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * @author zy zhangyi <zhangyi, 1104745049@QQ.com
 * @version v1.0
 * @project study1
 * @Description
 * @encoding UTF-8
 * @date 2018/10/15
 * @time 下午6:05
 * @修改记录 <pre>
 * 版本       修改人         修改时间         修改内容描述
 * --------------------------------------------------
 * <p>
 * --------------------------------------------------
 * </pre>
 */

public class TreatySetDialog extends Dialog {

    @BindView(R.id.treaty_tv_set)
    TextView mTreatyTvSet;
    @BindView(R.id.treaty_tv_guide)
    TextView mTreatyTvGuide;
    @BindView(R.id.treaty_tv_diss)
    TextView mTreatyTvDiss;

    public TreatySetDialog(@NonNull Context context) {
        super(context, R.style.coupon_style);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.treaty_set_dialog);
        ButterKnife.bind(this);

        mTreatyTvSet.setText(R.string.heyue_zhinan);
        mTreatyTvGuide.setText(R.string.heyue_jiaoyi_zhinan);

        //获取屏幕宽高
        DisplayMetrics displayMetrics = getContext().getResources().getDisplayMetrics();
        //屏幕宽
        int widthPixels = displayMetrics.widthPixels;
        //屏幕高
        int heightPixels = displayMetrics.heightPixels;
        WindowManager.LayoutParams attributes = getWindow().getAttributes();
        //设置给attributes
        attributes.width = (int) (widthPixels * 1);
        attributes.height = (int) (heightPixels * 0.3);
        //让Dialog位置居中
        attributes.gravity = Gravity.BOTTOM;
        getWindow().setAttributes(attributes);
        //点击空白处不dismiss
        setCanceledOnTouchOutside(true);


    }

    @OnClick({R.id.treaty_tv_set, R.id.treaty_tv_guide, R.id.treaty_tv_diss})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.treaty_tv_set:
                getContext().startActivity(new Intent(getContext(), WebActivity.class).putExtra("web_url", Config.URL + "mx/contractGuide_lists"));
                dismiss();
                break;
            case R.id.treaty_tv_guide:
                getContext().startActivity(new Intent(getContext(), WebActivity.class).putExtra("web_url", Config.URL + "mx/tradeGuide_lists"));
                dismiss();
                break;
            case R.id.treaty_tv_diss:
                this.dismiss();
                break;
        }
    }
}
